<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
<script>

var alphaApprox = 0, alphaMax = 0;
function testPixelShadow(pixel, reference) {
  var testPassed = true;
  for(i = 0; i < 3; i++)
    if(pixel[i] != reference[i]) {
        testPassed = false;
        break;
    }
  assert_true(testPassed);
  if(alphaMax != 0)
    assert_true(pixel[3] < alphaMax);
  else
    assert_approx_equals(pixel[3], reference[3], alphaApprox);
}

var canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.setAttribute('width', '400');
canvas.setAttribute('height', '650');
var ctx = canvas.getContext('2d');

ctx.shadowOffsetX = 200;
ctx.fillStyle = 'rgba(0, 0, 255, 1)';

ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
ctx.fillRect(50, 50, 100, 100);

ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
ctx.fillRect(50, 200, 100, 100);

ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
ctx.shadowBlur = 5;
ctx.fillRect(50, 350, 100, 100);

ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
ctx.fillRect(50, 500, 100, 100);

testSolidShadow =
    [
        ['testSolidShadow 1', ctx.getImageData(250, 50, 1, 1).data, [255, 0, 0, 255]],
        ['testSolidShadow 2', ctx.getImageData(250, 149, 1, 1).data, [255, 0, 0, 255]],
        ['testSolidShadow 3', ctx.getImageData(349, 50, 1, 1).data, [255, 0, 0, 255]],
        ['testSolidShadow 4', ctx.getImageData(349, 149, 1, 1).data, [255, 0, 0, 255]],
    ];

// alphaApprox = 5
testSolidAlphaShadow =
    [
        ['testSolidAlphaShadow 1', ctx.getImageData(250, 200, 1, 1).data, [255, 0, 0, 76]],
        ['testSolidAlphaShadow 2', ctx.getImageData(250, 299, 1, 1).data, [255, 0, 0, 76]],
        ['testSolidAlphaShadow 3', ctx.getImageData(349, 200, 1, 1).data, [255, 0, 0, 76]],
        ['testSolidAlphaShadow 4', ctx.getImageData(349, 299, 1, 1).data, [255, 0, 0, 76]],
    ];

// alpha < 25
testBlurryShadow =
    [
        ['testBlurryShadow 1', ctx.getImageData(248, 347, 1, 1).data, [255, 0, 0, 0]],
        ['testBlurryShadow 2', ctx.getImageData(248, 452, 1, 1).data, [255, 0, 0, 0]],
        ['testBlurryShadow 3', ctx.getImageData(351, 347, 1, 1).data, [255, 0, 0, 0]],
        ['testBlurryShadow 4', ctx.getImageData(351, 452, 1, 1).data, [255, 0, 0, 0]],
    ];

// alpha < 10
testBlurryAlphaShadow =
    [
        ['testBlurryAlphaShadow 1', ctx.getImageData(248, 497, 1, 1).data, [255, 0, 0, 0]],
        ['testBlurryAlphaShadow 2', ctx.getImageData(248, 602, 1, 1).data, [255, 0, 0, 0]],
        ['testBlurryAlphaShadow 3', ctx.getImageData(351, 497, 1, 1).data, [255, 0, 0, 0]],
        ['testBlurryAlphaShadow 4', ctx.getImageData(351, 602, 1, 1).data, [255, 0, 0, 0]],
    ];

generate_tests(testPixelShadow, testSolidShadow);
alphaApprox = 5;
generate_tests(testPixelShadow, testSolidAlphaShadow);
alphaMax = 25;
generate_tests(testPixelShadow, testBlurryShadow);
alphaMax = 10;
generate_tests(testPixelShadow, testBlurryAlphaShadow);

 </script>
</body>
